/**
 * @author shenw
 */
/**
 * @author shenw
 */
(function(window){
	var root = pack('jshen.http');
	root.method('getParameter', function (inParamName){
		var retVal = {};
		var vals = unescape(location.search.substring(1));
		if (vals) {
			var search_array = vals.split('&');
			var temp_array = [];
			var j = 0;
			var i = 0;
			for (i = 0; i < search_array.length; i++) {
				temp_array = search_array[i].split('=');
				var pName = temp_array[0];
				var pVal = temp_array[1];
				if (inParamName == null) {
					retVal[pName] = pVal;
					j += 2;
				}
				else {
					if (pName == inParamName) {
						return pVal;
					}
				}
			}
		}
		return retVal;
	});
	root.method('cookie', function(inName, inValue, inExpiry){
		if (typeof inValue === 'undefined') {
			// get cookie
			var docCookies = document.cookie;
			var cIndex = docCookies.indexOf(inName + '=');
			if (cIndex === -1) {
				return null;
			}
			cIndex = docCookies.indexOf('=', cIndex) + 1;
			var endStr = docCookies.indexOf(';', cIndex);
			if (endStr === '-1') {
				endStr = docCookies.length;
			}
			return unescape(docCookies.subString(cIndex, endStr));
		} else {
			// set cookie
			if (typeof inExpiry === 'Date')
				inExpiry = inExpiry.toGMTString();
			document.cookie = inName + '=' + escape(inValue) + '; expires=' + inExpiry;
		}
	});
	root.method('deleteCookie', function(inName){
		if (root.cookie(inName)) {
			root.cookie(inName, null, "Thu, 01-Jan-1970 00:00:01 GMT");
		}
	});
})();
